package com.atguigu.yygh.hosp.service.impl;


import com.atguigu.yygh.exception.YyghException;
import com.atguigu.yygh.hosp.mapper.HospitalSetMapper;
import com.atguigu.yygh.hosp.service.HospitalSetService;
import com.atguigu.yygh.hosp.utils.MD5;
import com.atguigu.yygh.model.hosp.HospitalSet;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 医院设置表 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2025-03-05
 */
@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {
    @Autowired
    private HospitalSetMapper hospitalSetMapper;

    @Override
    public String getSign(String hoscode) {
        HospitalSet oneByHoscode = this.getOneByHoscode(hoscode);
        if (null == oneByHoscode){
            throw new YyghException(20001, "该医院不存在");
        }
        String signKey = oneByHoscode.getSignKey();

        return  MD5.encrypt(signKey);
    }
    // 根据hoscode查询医院设置
    private HospitalSet getOneByHoscode(String hoscode) {
        return hospitalSetMapper.selectOne(new QueryWrapper<HospitalSet>().eq("hoscode", hoscode));
    }
}
